#include<bits/stdc++.h>
using namespace std;
#define int long long
int d[100005];
int v[100005];

signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int T;
	cin>>T;
	while(T--){
		memset(d,0,sizeof(d));
		memset(v,0,sizeof(v));
		int n=0,m=0,L=0,V=0,ans=0;
		cin>>n>>m>>L>>V;
		for(int i=1;i<=n;i++){
			int a;
			cin>>d[i]>>v[i]>>a;
		}
		int p,maxp=0;
		for(int i=1;i<=m;i++){cin>>p;maxp=max(maxp,p);}
		for(int i=1;i<=n;i++){
			if(d[i]<=maxp&&v[i]>V)ans++;
		}
		cout<<ans<<' ';
		if(ans==0)cout<<m<<endl;
		else cout<<m-1<<endl;
	}
	return 0;
	
}
































